package com.gx.gxreader.base

import java.lang.ref.WeakReference

abstract class BasePresenter<V> {

    //View接口类型的弱引用
    private var mViewRef: WeakReference<V>? = null

    fun attachView(view: V) {
        mViewRef = WeakReference(view)
    }

    protected fun getView() : V? = mViewRef?.get()

    fun isViewAttached() : Boolean = mViewRef != null && mViewRef?.get() != null

    fun detachView() {
        if (mViewRef != null) {
            mViewRef?.clear()
            mViewRef = null
        }
    }

    //每个Presenter都会有初始化的工作，可以在这里统一处理
    abstract fun start()
}